package com.exam.sacrifice.util;

import android.util.Log;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;

import com.exam.sacrifice.event.PlayMusicEvent;

import org.greenrobot.eventbus.EventBus;

public class AppLifecycleObserver implements LifecycleObserver {

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    public void onMoveToForeground() {
        Log.d("AppState", "App进入前台");
        EventBus.getDefault().post(new PlayMusicEvent(PlayMusicEvent.MUSIC_RESUME));
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    public void onMoveToBackground() {
        Log.d("AppState", "App进入后台");
        EventBus.getDefault().post(new PlayMusicEvent(PlayMusicEvent.MUSIC_PAUSE));
    }
}